#coding=utf-8
import bisect
def LIS():
    global n,nlist
    dp = []
    for i in range(n):
        temp = bisect.bisect_left(dp,nlist[i])
        if temp == len(dp):
            dp.append(nlist[i])
        else:
            dp[temp] = nlist[i]
    return len(dp)

def LCS(s1:str,s2:str)->list:
    n1 = len(s1)
    n2 = len(s2)
    dp = [[[0,''] for i in range(n2+1)] for j in range(n1+1)]
    for i in range(1,n1+1):
        for j in range(1,n2+1):
            if s1[i-1] == s2[j-1]:
                temp = dp[i-1][j-1]
                dp[i][j][0] = temp[0] + 1
                dp[i][j][1] = temp[1] + s1[i-1]
            else:
                dp[i][j] = max(dp[i][j-1],dp[i-1][j])
    return dp[-1][-1]

def player_game(a:list)->None:
    n = len(a)
    dp = [[0]*(n+1)]*(n+1)
    for i in range(n):
        dp[i][i] = a[i]
    for i in range(n-1,-1,-1):
        for j in range(i+1,n):
            summ = sum(a[i:j+1])
            dp[i][j] = summ - min(dp[i+1][j],dp[i][j-1])
    print(f'第一位玩家最终能得到{dp[0][n-1]}分,，第二位玩家最终能得到{sum(a)-dp[0][n-1]}分')



if __name__ == '__main__':
    #1
    # nlist = list(map(int,input("请输入序列： ").split()))
    # n = len(nlist)
    # print(f"最长上升子序列的长度为: {LIS()}")

    #2
    # s1 = input("请输入第一个字符串: ")
    # s2 = input("请输入第二个字符串: ")
    # res = LCS(s1,s2)
    # print(f'他们的最长公共子串长度为{res[0]},为{res[1]}')

    #3
    aa = [4,7,2,9,5,2]
    player_game(aa)